package com.bambooshoot.test;

import lombok.Data;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * 调用AI接口返回运营报告/风控报告主观数据
 *
 * @author mxc
 */
@Data
public class AIReportResponse {

    private int code;
    private String msg;
    private long timestamp;
    private AIData data;

    /**
     * 运营报告-业务发展问题
     */
    public String getFormattedBusinessDevelopmentIssues() {
        return convertToNumberedString(data.getBusinessDevelopmentIssues());
    }

    /**
     * 运营报告-下月工作计划
     */
    public String getFormattedNextMonthWorkPlan() {
        return convertToNumberedString(data.getNextMonthWorkPlan());
    }

    /**
     * 风控报告-主要问题
     */
    public String getFormattedMain_issues() {
        return convertToNumberedString(data.getMain_issues());
    }

    /**
     * 风控报告-措施
     */
    public String getFormattedMeasures() {
        return convertToNumberedString(data.getMeasures());
    }

    /**
     * 线程安全版序号转换
     *
     * @param list 待转换的字符串列表
     * @return 带有序号的字符串，每项占一行
     */
    public String convertToNumberedString(List<String> list) {
        if (list == null || list.isEmpty()) return "";

        AtomicInteger counter = new AtomicInteger(1);
        return list.stream()
            .map(item -> {
                // 1. 清除末尾所有标点（中英文）
                String cleaned = item.replaceAll("[\\p{P}\\p{Punct}]+$", "");
                // 2. 添加中文句号
                return cleaned + "。";
            })
            .map(item -> counter.getAndIncrement() + ". " + item) // 添加序号
            .collect(Collectors.joining("\n"));
    }

}
